//财务充值
$(function() {
	$("#forgetPwd").hide();
	var param = {};
	$.ajax({
				url : '/Lvscore_Advertiser_Maven/getBankInfo',
				data : param,
				type : 'POST',
				dataType : "json",
				success : function(json) {
					var mone=json.money;	 
					 //循环遍历数据添加到<div>中
		                $.each(json.list,function(index,val){
		                   $(".fastPayCardInfo").append("<input type='radio' name='fastPayRadio' />");		                		   
		                   $(".fastPayCardInfo").append('<label>'+val.bankName+'</label>');
		                   $(".fastPayCardInfo").append('<label>'+val.cardName+'</label>');
		                   $(".fastPayCardInfo").append('<label>储蓄卡</label>');
		                   $(".fastPayCardInfo").append('<span class="deviSpan">|</span>');
		                   $(".fastPayCardInfo").append('<label class="deviLabel">快捷</label></br>');
		                   //$(".fastPayCardInfo").append('<label>支付<span>'+mon+'元</span></label></br>'); 		                 
		                });
		                //用于存放未转化格式的金额(充值时使用)
		                $("#realMoney").val(json.realMoney);
		                
		                $("#payMoney").html("<i>支付</i>"+mone+"<i>元</i>");
		                //获取充值金额
		                $('#money').text(mone);
		                var payPwd=json.scorePayPwd;
		                if(payPwd!=""){
		                	//显示 “忘记密码” a标签
		                	$("#forgetPwd").show();
		                }
		                
		                
				},
				error : function(data) {
				}
				
			});

})
//添加快捷支付（判断是否已经设置过支付密码）
$("#chickPay").click(function(){
	   $.ajax({
		   url:'/Lvscore_Advertiser_Maven/judgePayPwd',
		   data:{},
		   type:'post',
		   dataType:'json',
		   success:function(json){
			   var pwd=json.scorePayPwd;
			   if(pwd=="0"){
					//未设置支付密码
					if(confirm("您还没有设置支付密码，前往设置。")){
						var path=escape('selectedNav=0&navPos=3');
						window.location.href = "/Lvscore_Advertiser_Maven/advertiserWeb/views/userCenter/recharge/checkMail.html?"+path;
					}
					
			   }else{
				   //已经设置支付密码(跳转到添加银行卡)
				   var path=escape('selectedNav=0&navPos=3');
					window.location.href = "/Lvscore_Advertiser_Maven/advertiserWeb/views/userCenter/recharge/addFastPay.html?"+path;
			   }
		   }
	   
		   
		   
	   });	
});

var path=escape('selectedNav=0&navPos=3');
//确认充值(快捷支付)
$("#cardPayBtn").click(function(){
	var money = $("#realMoney").val(),pwd=$("#payPwd").val();
	var phoneCode,bankPhone; 
	var param = {"money" : money,"pwd":pwd,"phoneCode":phoneCode,"bankPhone":bankPhone};
	//判断是否选择银行卡
	var va=$('input:radio[name="fastPayRadio"]:checked').val();
	if(va!=null){
		if(pwd!=null && ""!=pwd){
		$.ajax({
			url : '/Lvscore_Advertiser_Maven/updateBalance',	
			data : param,
			type : 'post',
			dataType:"json",
			success : function(json){
				if(json.status == -1){
					 $("#error_pwd").html(json.error);
					 var failed=json.error;
					 if(failed.equals("充值失败,请重新充值")){
						window.location.href ="/Lvscore_Advertiser_Maven/advertiserWeb/views/userCenter/recharge/saveFailed.html?"+path;
					 }
				  
				}else{
					window.location.href = "/Lvscore_Advertiser_Maven/advertiserWeb/views/userCenter/recharge/saveSuccess.html?"+path;
				}
			},
			error : function(){}	
		});
      }else{
    	  $("#error_pwd").html("*密码不能为空");
      }		
	}else{
		 $("#error_pwd").html("*请选择银行进行充值");
	}
	
});

//根据图片编号获取对应的银行名称
var bankName="建设银行";

function casebank(num){
 switch(num){
	case "2":
		bankName="中国工商银行";
		break;
	case "3":	
		bankName="中国银行";
		break;
	case "4":	
		bankName="中国农业银行";
		break;
	case "5":	
		bankName="中信银行";
		break;
	case "6":	
		bankName="兴业银行";
		break;
	case "7":	
		bankName="中国光大银行";
		break;
	case "8":	
		bankName="中国邮政";
		break;
	case "9":	
		bankName="北京银行";
		break;
	case "10":	
		bankName="平安银行";
		break;
	case "11":	
		bankName="中国民生银行";
		break;
	case "12":	
		bankName="交通银行";
	    break;
	case "13":	
		bankName="浦发银行";
		break;
	case "14":	
		bankName="招商银行";
		break;
	case "15":	
		bankName="广发银行";
		break;
	}
}



//银行卡充值
$("#fastPayBtn").click(function(){
	var num=$('input:radio[name="bankCard"]:checked').val();
	if(num!=null){
		var money=$("#realMoney").val();
		casebank(num);//获取对应的银行名称
		$.ajax({
			url:'/Lvscore_Advertiser_Maven/setBankImg',
			data:{count:num,bankName:bankName,money:money},
			type:'post',
			dataType:'json',
			success:function(json){
		         window.location.href = "/Lvscore_Advertiser_Maven/advertiserWeb/views/userCenter/recharge/accountRecharge.html?"+path;
			}
		});
		
	}else{
		$("#error_pay").html("*请选择银行进行充值");
	}

});





